<?php
/**
 * Created by PhpStorm.
 * User: peter
 * Date: 2018/6/2
 * Time: 下午4:34
 */

namespace app\admin\controller;

use app\admin\logic\Member;
use app\model\ActivityOrderAttach;
use app\model\TbTravelPeople;
use app\model\TravelPeople;
use extend\Functions;

class Test extends Base
{
    /***
     * @return \think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function test () {
        return Member::migration();
    }
    public function migrationTravel ()
    {
        $tbTravel = new TbTravelPeople();
        $travel = new TravelPeople();
        $items = $tbTravel->select();
        $member = new \app\model\Member();
        $data = [];
        foreach ($items as $item) {
            $uid = $member->where('old_sys_uid', $item->memberId)->value('uid');
            array_push($data, [
               'uid' =>  $uid ? $uid : 0,
                'name' => $item->fullname,
                'sex' => $item->sex,
                'type' => $item->theType,
                'mobile' => $item->tel,
                'certificate_type' => $item->cardType,
                'certificate_number' => $item->idcard
            ]);
        }
        $travel->saveAll($data);
        return Functions::result();
    }
}